# coding:utf-8
from datetime import date
from flask import Flask as _Flask
from flask.json import JSONEncoder as _JSONEncoder
from werkzeug.exceptions import Forbidden


class JSONEncoder(_JSONEncoder):
    def default(self, o):
        if hasattr(o, 'keys') and hasattr(o, '__getitem__'):
            return dict(o)
        if isinstance(o, date):
            if date is None:
                return '暂无'
            else:
                return o.strftime('%Y-%m-%d')
        raise Forbidden()
        # return o.__dict__


class Flask(_Flask):
    json_encoder = JSONEncoder
